package com.tianzeculture.stagebao.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.tianzeculture.stagebao.R;
import com.tianzeculture.stagebao.network.util.DensityUtil;

/**
 * Created by Administrator on 2018/5/24 0024.
 */

public class PublicationDialog {

    private Dialog dialog;
    private OnSelectClickListener onSelectClickListener;
    private int type;

    public PublicationDialog(Context context, int type) {
        init(context);
        this.type = type;
    }

    private void init(final Context context) {
        dialog = new Dialog(context, R.style.DialogPushUpInAnimStyle);
        dialog.setContentView(R.layout.dialog_publication);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setCancelable(true);

        Window window = dialog.getWindow();
        WindowManager.LayoutParams layoutParams = window.getAttributes();

        layoutParams.width = DensityUtil.getScreenWidth(context);
        layoutParams.gravity = Gravity.BOTTOM;
        window.setAttributes(layoutParams);

        TextView tvTakePicture = (TextView) window.findViewById(R.id.tvTakePicture);
        tvTakePicture.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                choicePic(true, type);
            }
        });
        TextView tvSelectAlbum = (TextView) window.findViewById(R.id.tvSelectAlbum);
        tvSelectAlbum.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                choicePic(false, type);
            }
        });
        TextView tvCancel = (TextView) window.findViewById(R.id.tvCancel);
        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

    }

    private void choicePic(boolean isTakePic, int type) {
        if (onSelectClickListener != null) {
            onSelectClickListener.onOk(isTakePic, type);
        }
        dismiss();
    }


    /**
     *
     */
    public void show() {
        dialog.show();
    }

    /**
     *
     */
    public void dismiss() {
        dialog.dismiss();
        if (onSelectClickListener != null) {
            onSelectClickListener.onCancel();
        }
    }

    public OnSelectClickListener getOnSelectClickListener() {
        return onSelectClickListener;
    }

    public void setOnSelectClickListener(OnSelectClickListener onSelectClickListener) {
        this.onSelectClickListener = onSelectClickListener;
    }


    public interface OnSelectClickListener {
        void onOk(boolean isTakePic, int type);

        void onCancel();
    }
}
